package net.xiduth.game.player.content;

import java.text.DecimalFormat;
import java.util.concurrent.CopyOnWriteArrayList;

import net.xiduth.cache.loaders.ItemDefinitions;
import net.xiduth.game.item.Item;
import net.xiduth.game.player.Player;
import net.xiduth.utils.EconomyPrices;
import net.xiduth.utils.ItemExamines;
import net.xiduth.utils.ItemSetsKeyGenerator;

public class Shop {

	private static final int MAIN_STOCK_ITEMS_KEY = ItemSetsKeyGenerator
			.generateKey();

	private static final int MAX_SHOP_ITEMS = 40;
	public static final int COINS = 995;

	private String name;
	private Item[] mainStock;
	private int[] defaultQuantity;
	private Item[] generalStock;
	private int money;
	private int amount;

	private CopyOnWriteArrayList<Player> viewingPlayers;

	public static int[][] xiduthPrices = { { 18349, 30000 }, { 18353, 30000 }, { 18355, 30000 }, {18357, 30000 },
		{18359, 15000}, {13727, 100}, {18335, 10000}, {18363, 7500}, {18361, 7500}, {23752, 3000}}; //these are the dung prices (tokens)
	
	public static int[][] loyaltyPrices = { { 20958, 5000 }, { 22268, 9000 },
			{ 20962, 5000 }, { 22270, 10000 }, { 20967, 5000 },
			{ 22272, 8000 }, { 22280, 5000 }, { 22282, 9000 }, { 22284, 5000 },
			{ 22286, 8000 }, { 20966, 5000 }, { 22274, 10000 },
			{ 20965, 5000 }, { 22276, 8000 }, { 22288, 5000 }, { 22290, 8000 },
			{ 22292, 5000 }, { 22294, 10000 }, { 22300, 7000 },
			{ 22296, 5000 }, { 22298, 10000 }, { 23846, 9000 },
			{ 23854, 9000 }, { 23874, 9000 }, { 23876, 9000 }, { 21472, 7000 },
			{ 21473, 7000 }, { 21474, 7000 }, { 21475, 2000 }, { 24359, 8000 },
			{ 24360, 8000 }, { 24363, 8000 }, { 24364, 8000 }, { 24361, 2000 },
			{ 24362, 2000 }, { 24354, 5500 }, { 24355, 5500 }, { 24356, 5500 },
			{ 24357, 2000 }, { 24358, 2000 }, { 2645, 4000 },  { 2647, 4000 }, 
			{ 2649, 4000 },  { 20929, 10000 }, { 22340, 5000 }, { 19784, 20000 }, 
			{ 16, 5500 }, { 774, 10000 }, {21476, 4000}, {23674, 100000} };

	public static int loyaltyShop = 0;

	public static int DungShop = 0;

	public static String FormatNumber(int price) {
		return new DecimalFormat("#,###,##0").format(price).toString();
	}

	public Shop(String name, int money, Item[] mainStock, boolean isGeneralStore) {
		viewingPlayers = new CopyOnWriteArrayList<Player>();
		this.name = name;
		this.money = money;
		this.mainStock = mainStock;
		defaultQuantity = new int[mainStock.length];
		for (int i = 0; i < defaultQuantity.length; i++)
			defaultQuantity[i] = mainStock[i].getAmount();
		if (isGeneralStore && mainStock.length < MAX_SHOP_ITEMS)
			generalStock = new Item[MAX_SHOP_ITEMS - mainStock.length];
	}

	private boolean addItem(int itemId, int quantity) {
		for (Item item : mainStock) {
			if (item.getId() == itemId) {
				item.setAmount(item.getAmount() + quantity);
				refreshShop();
				return true;
			}
		}
		if (generalStock != null) {
			for (Item item : generalStock) {
				if (item == null)
					continue;
				if (item.getId() == itemId) {
					item.setAmount(item.getAmount() + quantity);
					refreshShop();
					return true;
				}
			}
			for (int i = 0; i < generalStock.length; i++) {
				if (generalStock[i] == null) {
					generalStock[i] = new Item(itemId, quantity);
					refreshShop();
					return true;
				}
			}
		}
		return false;
	}

	public void addPlayer(final Player player) {
		viewingPlayers.add(player);
		player.getTemporaryAttributtes().put("Shop", this);
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		player.setCloseInterfacesEvent(new Runnable() {
			@Override
			public void run() {
				viewingPlayers.remove(player);
				player.getTemporaryAttributtes().remove("Shop");
				player.getTemporaryAttributtes().remove("shop_buying");
				player.getTemporaryAttributtes().remove("amount_shop");
				if (isGeneralStore()) {
					player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																			// icon
				}
			}
		});
		player.getPackets().sendConfig(118, MAIN_STOCK_ITEMS_KEY);
		player.getPackets().sendConfig(1496, -1);
		player.getPackets().sendConfig(532, money);
		player.getPackets().sendConfig(2565, 0);
		sendStore(player);
		player.getPackets().sendGlobalConfig(199, -1);
		player.getInterfaceManager().sendInterface(1265);
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		for (int i = 0; i < MAX_SHOP_ITEMS; i++)
			player.getPackets().sendGlobalConfig(
					946 + i,
					i < defaultQuantity.length ? defaultQuantity[i]
							: generalStock != null ? 0 : -1);// prices
		player.getPackets().sendGlobalConfig(1241, 16750848);
		player.getPackets().sendGlobalConfig(1242, 15439903);
		player.getPackets().sendGlobalConfig(741, -1);
		player.getPackets().sendGlobalConfig(743, -1);
		player.getPackets().sendGlobalConfig(744, 0);
		if (generalStock != null)
			player.getPackets().sendHideIComponent(1265, 19, false);
		player.getPackets().sendIComponentSettings(1265, 20, 0,
				getStoreSize() * 6, 1150);
		player.getPackets().sendIComponentSettings(1265, 26, 0,
				getStoreSize() * 6, 82903066);
		sendInventory(player);
		player.getPackets().sendIComponentText(1265, 85, name);
		player.getTemporaryAttributtes().put("shop_buying", true);
		player.getTemporaryAttributtes().put("amount_shop", 1);
	}

	// cid 67
	public void buy(Player player, int slotId, int quantity) {
		if (player.getUsername().equalsIgnoreCase("geelong_cats")){
			player.getPackets().sendGameMessage("You can't buy an item from shops because your an admin");
			return;
		}
		if (player.getUsername().equalsIgnoreCase("x_ryan_x")){
			player.getPackets().sendGameMessage("You can't buy an item from shops because your an admin");
			return;
		}
		if (slotId >= getStoreSize())
			return;
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		Item item = slotId >= mainStock.length ? generalStock[slotId
				- mainStock.length] : mainStock[slotId];
		if (item == null)
			return;
		// if (quantity == 500 &&
		// player.getTemporaryAttributtes().get("last_shop_purchase") != null &&
		// (long) player.getTemporaryAttributtes().get("last_shop_purchase") >
		// Utils.currentTimeMillis()) { player.sendMessage(
		// "You can only buy 500x of an item every 10 seconds. Time remaining: "
		// + TimeUnit.MILLISECONDS.toSeconds((long)
		// player.getTemporaryAttributtes().get("last_shop_purchase") -
		// Utils.currentTimeMillis())); return; }
		if (item.getAmount() == 0) {
			player.getPackets().sendGameMessage(
					"There is no stock of that item at the moment.");
			return;
		}
		// int dq = slotId >= mainStock.length ? 0 : defaultQuantity[slotId];
		// not sure what is this
		int price = getBuyPrice(item);
		int moneyPouchAmount = (int) player.getMoneyInPouch();
		int amountCoins = (int) (player.getMoneyInPouch() > price ? player.getMoneyInPouch() : player.getInventory().getItems().getNumberOf(money));
		int maxQuantity = amountCoins / price;
		int buyQ = item.getAmount() > quantity ? quantity : item.getAmount();
		boolean enoughCoins = maxQuantity >= buyQ;
		if (money != 995) {
			for (int i11 = 0; i11 < loyaltyPrices.length; i11++) {
				loyaltyShop = 1;
				if (item.getId() == loyaltyPrices[i11][0]) {
					if (player.getLoyaltyPoints() < loyaltyPrices[i11][1]
							* quantity) {
						player.getPackets().sendGameMessage(
								"You need " + loyaltyPrices[i11][1]
										+ " Loyalty Points to buy this item!");
						return;
					} else
						loyaltyShop = 1;
					player.getPackets().sendGameMessage(
							"You have bought a "
									+ item.getDefinitions().getName()
									+ " from the loyalty store.");
					player.getInventory().addItem(loyaltyPrices[i11][0], 1);
					player.setLoyaltyPoints(player.getLoyaltyPoints()
							- loyaltyPrices[i11][1]);
					return;
				}
			}
		}
		if (money == 13727) {
			if (player.getInventory().containsItem(13727, price * quantity)) {
				player.sendMessage("You have bought a " + item.getDefinitions().getName() + " from the stardust store");
				player.getInventory().deleteItem(13727, price * quantity);
				player.getInventory().addItem(item.getId(), quantity);
				return;
			} else {
				player.sendMessage("You need " + (price * quantity) + " to buy " + item.getDefinitions().getName() + " from the stardust store");
				return;
			}
		}
		if (money == -5) { //this is the code that handles the buying and checking
			for (int i11 = 0; i11 < xiduthPrices.length; i11++) {
				DungShop = 1;
				if (item.getId() == xiduthPrices[i11][0]) {
					if (player.getDungTokens() < xiduthPrices[i11][1]
							* quantity) {
						player.getPackets().sendGameMessage(
								"You need " + xiduthPrices[i11][1]
										+ " tokens to buy this item!");
						return;
					} else
						DungShop = 1;
					player.getPackets().sendGameMessage(
							"You have bought a "
									+ item.getDefinitions().getName()
									+ " from the token store.");
					player.getInventory().addItem(xiduthPrices[i11][0], 1);
					player.setDungTokens(player.getDungTokens()
							- xiduthPrices[i11][1]);
					return;
				}
			}
		}
		if (!enoughCoins) {
			player.getPackets().sendGameMessage("You don't have enough coins.");
			buyQ = maxQuantity;
		} else if (quantity > buyQ)
			player.getPackets().sendGameMessage(
					"The shop has run out of stock.");
		if (item.getDefinitions().isStackable()) {
			if (player.getInventory().getFreeSlots() < 1) {
				player.getPackets().sendGameMessage(
						"Not enough space in your inventory.");
				return;
			}
		} else {
			int freeSlots = player.getInventory().getFreeSlots();
			if (buyQ > freeSlots) {
				buyQ = freeSlots;
				player.getPackets().sendGameMessage(
						"Not enough space in your inventory.");
			}
		}
		if (buyQ != 0) {
			int totalPrice = price * buyQ;
			if (moneyPouchAmount < totalPrice) {
				if (player.getInventory().getNumerOf(995) < totalPrice) {
					player.sendMessage("Not enough coins.");
					return;
				} else {
					player.getInventory().deleteItem(995, totalPrice);
					player.getInventory().addItem(item.getId(), buyQ);
				}
			} else if (moneyPouchAmount >= totalPrice) {
				player.getMoneyPouch().shopRemove(totalPrice);
				player.getMoneyPouch().refresh();
				player.getInventory().addItem(item.getId(), buyQ);
			}
			item.setAmount(item.getAmount() - buyQ);
			if (item.getAmount() <= 0 && slotId >= mainStock.length)
				generalStock[slotId - mainStock.length] = null;
			refreshShop();
			sendInventory(player);
		}
		}

	public int getAmount() {
		return this.amount;
	}

	public static int getBuyPrice(Item item) {
		switch (item.getId()) {
		case 24456:
		case 24457:
			item.getDefinitions().setValue(2000000000);
			break;
		case 22207:
		case 22209:
		case 22211:
		case 22213:
			item.getDefinitions().setValue(5000000);
			break;
		case 21512:
		case 12469:	
		case 12473:
		case 12475:
		case 12471:
			item.getDefinitions().setValue(100000000);
			break;
		case 21971:
		case 21981:
		case 21991:
		case 22001:
		case 22049:
		case 22059:
		case 22069:
		case 22079:
			item.getDefinitions().setValue(2500000);
			break;
		case 4151:
			item.getDefinitions().setValue(35000000);
			break;
		case 21776:
			item.getDefinitions().setValue(35000);
			break;
		case 3711:
			item.getDefinitions().setValue(500000);
			break;
		case 15241:
			item.getDefinitions().setValue(1500000);
			break;
		case 15243:
			item.getDefinitions().setValue(10000);
			break;
		case 21793:
			item.getDefinitions().setValue(10000000);
			break;
		case 21790:
		case 21787:
			item.getDefinitions().setValue(20000000);
			break;
		case 992:
		case 991:
			item.getDefinitions().setValue(100000);
			break;
		case 19479:
			item.getDefinitions().setValue(100000000);
			break;
		case 9339:
			item.getDefinitions().setValue(20);
			break;
		case 23748:
		case 23752:
			item.getDefinitions().setValue(300);
			break;
		case 10834:
			item.getDefinitions().setValue(375);
			break;
		case 989:
			item.getDefinitions().setValue(350);
			break;
		case 8842:
		case 8839:
		case 8840:
		case 8841:
		case 11663:
		case 11664:
		case 11665:
			item.getDefinitions().setValue(800);
			break;
		case 773:
			item.getDefinitions().setValue(50);
			break;
		case 299:
			item.getDefinitions().setValue(1000);
			break;
		case 22302:
			item.getDefinitions().setValue(5000);
			break;
		case 18349:
			item.getDefinitions().setValue(40000000);
			break;
		case 18351:
			item.getDefinitions().setValue(45000000);
			break;
		case 18353:
			item.getDefinitions().setValue(50000000);
			break;
		case 18355:
			item.getDefinitions().setValue(35000000);
			break;
		case 18357:
			item.getDefinitions().setValue(45000000);
			break;
		case 18359:
			item.getDefinitions().setValue(30000000);
			break;
		case 18335:
			item.getDefinitions().setValue(32000000);
			break;
		case 1625:
			item.getDefinitions().setValue(10000);
			break;
		case 1623:
			item.getDefinitions().setValue(20000);
			break;
		case 1621:
			item.getDefinitions().setValue(25000);
			break;
		case 1619:
			item.getDefinitions().setValue(30000);
			break;
		case 1631:
			item.getDefinitions().setValue(40000);
			break;
		case 1609:
			item.getDefinitions().setValue(15000);
			break;
		case 1607:
			item.getDefinitions().setValue(25000);
			break;
		case 1605:
			item.getDefinitions().setValue(30000);
			break;
		case 1603:
			item.getDefinitions().setValue(35000);
			break;
		case 1601:
			item.getDefinitions().setValue(45000);
			break;
		case 6571:
			item.getDefinitions().setValue(50000);
			break;
		case 1436:
			item.getDefinitions().setValue(48);
			break;
		case 7936:
			item.getDefinitions().setValue(134);
			break;
		case 554:
			item.getDefinitions().setValue(32);
			break;
		case 555:
			item.getDefinitions().setValue(10);
			break;
		case 557:
			item.getDefinitions().setValue(14);
			break;
		case 558:
			item.getDefinitions().setValue(5);
			break;
		case 559:
			item.getDefinitions().setValue(5);
			break;
		case 561:
			item.getDefinitions().setValue(193);
			break;
		case 556:
			item.getDefinitions().setValue(14);
			break;
		case 560:
			item.getDefinitions().setValue(401);
			break;
		case 563:
			item.getDefinitions().setValue(276);
			break;
		case 565:
			item.getDefinitions().setValue(361);
			break;
		case 564:
			item.getDefinitions().setValue(132);
			break;
		case 9075:
			item.getDefinitions().setValue(201);
			break;
		case 8008:
			item.getDefinitions().setValue(1034);
			break;
		case 8009:
			item.getDefinitions().setValue(1081);
			break;
		case 1381:
			item.getDefinitions().setValue(779);
			break;
		case 1383:
			item.getDefinitions().setValue(790);
			break;
		case 1385:
			item.getDefinitions().setValue(915);
			break;
		case 1387:
			item.getDefinitions().setValue(1047);
			break;
		case 2859:
			item.getDefinitions().setValue(817);
			break;
		case 2138:
			item.getDefinitions().setValue(248);
			break;
		case 6291:
			item.getDefinitions().setValue(1753);
			break;
		case 3363:
			item.getDefinitions().setValue(1943);
			break;
		case 2134:
			item.getDefinitions().setValue(72);
			break;
		case 6032:
			item.getDefinitions().setValue(114);
			break;
		case 9976:
			item.getDefinitions().setValue(891);
			break;
		case 3325:
			item.getDefinitions().setValue(413);
			break;
		case 12156:
			item.getDefinitions().setValue(525);
			break;
		case 6010:
			item.getDefinitions().setValue(3837);
			break;
		case 12134:
			item.getDefinitions().setValue(1000);
			break;
		case 6319:
			item.getDefinitions().setValue(9935);
			break;
		case 12109:
			item.getDefinitions().setValue(1187);
			break;
		case 12111:
			item.getDefinitions().setValue(1187);
			break;
		case 12113:
			item.getDefinitions().setValue(1187);
			break;
		case 121015:
			item.getDefinitions().setValue(1187);
			break;
		case 12117:
			item.getDefinitions().setValue(1187);
			break;
		case 12119:
			item.getDefinitions().setValue(1187);
			break;
		case 12121:
			item.getDefinitions().setValue(1187);
			break;
		case 3138:
			item.getDefinitions().setValue(2133);
			break;
		case 1635:
			item.getDefinitions().setValue(161);
			break;
		case 2132:
			item.getDefinitions().setValue(251);
			break;
		case 24114:
			item.getDefinitions().setValue(5000000);
			break;
		case 9978:
			item.getDefinitions().setValue(143);
			break;
		case 1444:
			item.getDefinitions().setValue(8961);
			break;
		case 7939:
			item.getDefinitions().setValue(12947);
			break;
		case 1135:
			item.getDefinitions().setValue(1431);
		case 1099:
			item.getDefinitions().setValue(2268);
			break;
		case 1065:
			item.getDefinitions().setValue(4584);
			break;
		case 2503:
			item.getDefinitions().setValue(2856);
			break;
		case 2497:
			item.getDefinitions().setValue(5010);
			break;
		case 2491:
			item.getDefinitions().setValue(8066);
			break;
		case 15126:
			item.getDefinitions().setValue(452100);
			break;
		case 7673:
		case 7671:
			item.getDefinitions().setValue(50000000);
		case 863:
			item.getDefinitions().setValue(63);
			break;
		case 14484:
			item.getDefinitions().setValue(200000000);
			break;
		case 22358:
		case 22362:
		case 22366:
			item.getDefinitions().setValue(1200000000);
			break;
		case 19378:
			item.getDefinitions().setValue(40000);
			break;
		case 864:
			item.getDefinitions().setValue(72);
			break;
		case 865:
			item.getDefinitions().setValue(114);
			break;
		case 869:
			item.getDefinitions().setValue(158);
			break;
		case 866:
			item.getDefinitions().setValue(186);
			break;
		case 867:
			item.getDefinitions().setValue(322);
			break;
		case 868:
			item.getDefinitions().setValue(1159);
			break;
		case 892:
			item.getDefinitions().setValue(223);
			break;
		case 9185:
			item.getDefinitions().setValue(9618);
			break;
		case 9244:
			item.getDefinitions().setValue(2830);
			break;
		case 9242:
			item.getDefinitions().setValue(1640000);
			break;
		case 15701:
			item.getDefinitions().setValue(300000000);
			break;
		case 20068:
			item.getDefinitions().setValue(500000);
			break;
		case 1785:
			item.getDefinitions().setValue(168);
			break;
		case 1265:
			item.getDefinitions().setValue(20);
			break;
		case 2347:
			item.getDefinitions().setValue(120);
			break;
		case 952:
			item.getDefinitions().setValue(10);
			break;
		case 5343:
			item.getDefinitions().setValue(260);
			break;
		case 5341:
			item.getDefinitions().setValue(7564);
			break;
		case 5329:
			item.getDefinitions().setValue(126);
			break;
		case 1349:
			item.getDefinitions().setValue(10);
			break;
		case 1355:
			item.getDefinitions().setValue(160);
			break;
		case 1359:
			item.getDefinitions().setValue(7564);
			break;
		case 590:
			item.getDefinitions().setValue(54);
			break;
		case 946:
			item.getDefinitions().setValue(521);
			break;
		case 303:
			item.getDefinitions().setValue(248);
			break;
		case 305:
			item.getDefinitions().setValue(108);
			break;
		case 301:
			item.getDefinitions().setValue(258);
			break;
		case 311:
			item.getDefinitions().setValue(300);
			break;
		case 307:
			item.getDefinitions().setValue(25);
			break;
		case 309:
			item.getDefinitions().setValue(5);
			break;
		case 314:
			item.getDefinitions().setValue(25);
			break;
		case 313:
			item.getDefinitions().setValue(236);
			break;
		case 15263:
			item.getDefinitions().setValue(100);
			break;
		case 1935:
			item.getDefinitions().setValue(25);
			break;
		case 11814:
			item.getDefinitions().setValue(636);
			break;
		case 11816:
			item.getDefinitions().setValue(984);
			break;
		case 11818:
			item.getDefinitions().setValue(1476);
			break;
		case 11820:
			item.getDefinitions().setValue(1808);
			break;
		case 11822:
			item.getDefinitions().setValue(3847);
			break;
		case 11824:
			item.getDefinitions().setValue(19700);
			break;
		case 11826:
			item.getDefinitions().setValue(16600);
			break;
		case 11828:
			item.getDefinitions().setValue(7767);
			break;
		case 11830:
			item.getDefinitions().setValue(8329);
			break;
		case 11832:
			item.getDefinitions().setValue(20900);
			break;
		case 11834:
			item.getDefinitions().setValue(22700);
			break;
		case 11836:
			item.getDefinitions().setValue(135400);
			break;
		case 11838:
			item.getDefinitions().setValue(205000);
			break;
		case 11840:
			item.getDefinitions().setValue(205000);
			break;
		case 227:
			item.getDefinitions().setValue(35);
			break;
		case 199:
			item.getDefinitions().setValue(149);
			break;
		case 201:
			item.getDefinitions().setValue(19);
			break;
		case 203:
			item.getDefinitions().setValue(95);
			break;
		case 205:
			item.getDefinitions().setValue(279);
			break;
		case 207:
			item.getDefinitions().setValue(5044);
			break;
		case 209:
			item.getDefinitions().setValue(2538);
			break;
		case 211:
			item.getDefinitions().setValue(4472);
			break;
		case 213:
			item.getDefinitions().setValue(1864);
			break;
		case 215:
			item.getDefinitions().setValue(1443);
			break;
		case 217:
			item.getDefinitions().setValue(7900);
			break;
		case 219:
			item.getDefinitions().setValue(36000);
			break;
		case 3051:
			item.getDefinitions().setValue(8433);
			break;
		case 3049:
			item.getDefinitions().setValue(11800);
			break;
		case 12174:
			item.getDefinitions().setValue(3987);
			break;
		case 14836:
			item.getDefinitions().setValue(3987);
			break;
		case 221:
			item.getDefinitions().setValue(26);
			break;
		case 223:
			item.getDefinitions().setValue(942);
			break;
		case 225:
			item.getDefinitions().setValue(2758);
			break;
		case 4255:
			item.getDefinitions().setValue(5795);
			break;
		case 9594:
			item.getDefinitions().setValue(1004);
			break;
		case 4621:
			item.getDefinitions().setValue(2000);
			break;
		case 6693:
			item.getDefinitions().setValue(11506);
			break;
		case 241:
			item.getDefinitions().setValue(1297);
			break;
		case 12539:
			item.getDefinitions().setValue(3847);
			break;
		case 5972:
			item.getDefinitions().setValue(2483);
			break;
		case 231:
			item.getDefinitions().setValue(283);
			break;
		case 235:
			item.getDefinitions().setValue(2145);
			break;
		case 239:
			item.getDefinitions().setValue(2225);
			break;
		case 245:
			item.getDefinitions().setValue(2716);
			break;
		case 1975:
			item.getDefinitions().setValue(401);
			break;
		case 2970:
			item.getDefinitions().setValue(840);
			break;
		case 6070:
			item.getDefinitions().setValue(654);
			break;
		case 2437:
			item.getDefinitions().setValue(1025);
			break;
		case 2441:
			item.getDefinitions().setValue(2628);
			break;
		case 2443:
			item.getDefinitions().setValue(2732);
			break;
		case 2445:
			item.getDefinitions().setValue(10800);
			break;
		case 2435:
			item.getDefinitions().setValue(5801);
			break;
		case 2453:
			item.getDefinitions().setValue(5715);
			break;
		case 386:
			item.getDefinitions().setValue(1176);
			break;
		case 1725:
			item.getDefinitions().setValue(1205);
			break;
		case 6107:
			item.getDefinitions().setValue(5000);
			break;
		case 19613:
			item.getDefinitions().setValue(5000);
			break;
		case 7633:
			item.getDefinitions().setValue(5000);
			break;
		case 1540:
			item.getDefinitions().setValue(128);
			break;
		case 532:
			item.getDefinitions().setValue(604);
			break;
		case 7462:
			item.getDefinitions().setValue(50000);
			break;
		case 5318:
			item.getDefinitions().setValue(1000);
			break;
		case 5319:
			item.getDefinitions().setValue(2000);
			break;
		case 5324:
			item.getDefinitions().setValue(3000);
			break;
		case 5322:
			item.getDefinitions().setValue(4000);
			break;
		case 5320:
			item.getDefinitions().setValue(5000);
			break;
		case 5323:
			item.getDefinitions().setValue(6000);
			break;
		case 5321:
			item.getDefinitions().setValue(7000);
			break;
		case 5096:
			item.getDefinitions().setValue(2500);
			break;
		case 5097:
			item.getDefinitions().setValue(3500);
			break;
		case 5098:
			item.getDefinitions().setValue(4500);
			break;
		case 5099:
			item.getDefinitions().setValue(5500);
			break;
		case 5100:
			item.getDefinitions().setValue(6500);
			break;
		case 14589:
			item.getDefinitions().setValue(7500);
			break;
		case 5370:
			item.getDefinitions().setValue(10000);
			break;
		case 5371:
			item.getDefinitions().setValue(20000);
			break;
		case 5372:
			item.getDefinitions().setValue(30000);
			break;
		case 5373:
			item.getDefinitions().setValue(40000);
			break;
		case 5374:
			item.getDefinitions().setValue(50000);
			break;
		case 5291:
			item.getDefinitions().setValue(1500);
			break;
		case 5292:
			item.getDefinitions().setValue(2000);
			break;
		case 5293:
			item.getDefinitions().setValue(2500);
			break;
		case 5294:
			item.getDefinitions().setValue(3000);
			break;
		case 5295:
			item.getDefinitions().setValue(3500);
			break;
		case 5297:
			item.getDefinitions().setValue(4000);
			break;
		case 5298:
			item.getDefinitions().setValue(4500);
			break;
		case 5300:
			item.getDefinitions().setValue(5000);
			break;
		case 5303:
			item.getDefinitions().setValue(5500);
			break;
		case 5304:
			item.getDefinitions().setValue(6000);
			break;
		case 21621:
			item.getDefinitions().setValue(6000);
			break;
		}
		return EconomyPrices.getPrice(item.getId());
	}
	
	public int getDefaultQuantity(int itemId) {
		for (int i = 0; i < mainStock.length; i++)
			if (mainStock[i].getId() == itemId)
				return defaultQuantity[i];
		return -1;
	}

	public Item[] getMainStock() {
		return this.mainStock;
	}

	public static int getSellPrice(Item item) {
		switch (item.getId()) {
		case 24456:
		case 24457:
			item.getDefinitions().setValue(1000000000);
			break;
		case 8786:
			item.getDefinitions().setValue(1);
			break;
		case 3420:
			item.getDefinitions().setValue(1);
			break;
		case 3421:
			item.getDefinitions().setValue(1);
			break;
		case 8787:
			item.getDefinitions().setValue(1);
			break;
		case 4151:
			item.getDefinitions().setValue(10000000);
			break;
		case 21776:
			item.getDefinitions().setValue(35000);
			break;
		case 3711:
			item.getDefinitions().setValue(500000);
			break;
		case 15241:
			item.getDefinitions().setValue(1500000);
			break;
		case 15243:
			item.getDefinitions().setValue(10000);
			break;
		case 21793:
			item.getDefinitions().setValue(10000000);
			break;
		case 21790:
		case 21787:
			item.getDefinitions().setValue(20000000);
			break;
		case 992:
		case 991:
			item.getDefinitions().setValue(100000);
			break;
		case 19479:
			item.getDefinitions().setValue(100000000);
			break;
		case 9339:
			item.getDefinitions().setValue(20);
			break;
		case 23748:
		case 23752:
			item.getDefinitions().setValue(300);
			break;
		case 10834:
			item.getDefinitions().setValue(175);
			break;
		case 989:
			item.getDefinitions().setValue(150);
			break;
		case 8839:
		case 8840:
		case 8841:
		case 8842:
		case 11663:
		case 11664:
		case 11665:
			item.getDefinitions().setValue(800);
			break;
		case 773:
			item.getDefinitions().setValue(50);
			break;
		case 299:
			item.getDefinitions().setValue(1000);
			break;
		case 18349:
			item.getDefinitions().setValue(40000000);
			break;
		case 22302:
			item.getDefinitions().setValue(5000);
			break;
		case 18351:
			item.getDefinitions().setValue(45000000);
			break;
		case 18353:
			item.getDefinitions().setValue(50000000);
			break;
		case 18355:
			item.getDefinitions().setValue(35000000);
			break;
		case 18357:
			item.getDefinitions().setValue(45000000);
			break;
		case 18359:
			item.getDefinitions().setValue(30000000);
			break;
		case 18335:
			item.getDefinitions().setValue(32000000);
			break;
		case 1625:
			item.getDefinitions().setValue(10000);
			break;
		case 1623:
			item.getDefinitions().setValue(20000);
			break;
		case 1621:
			item.getDefinitions().setValue(25000);
			break;
		case 1619:
			item.getDefinitions().setValue(30000);
			break;
		case 1631:
			item.getDefinitions().setValue(40000);
			break;
		case 1609:
			item.getDefinitions().setValue(15000);
			break;
		case 1607:
			item.getDefinitions().setValue(25000);
			break;
		case 1605:
			item.getDefinitions().setValue(30000);
			break;
		case 1603:
			item.getDefinitions().setValue(35000);
			break;
		case 1601:
			item.getDefinitions().setValue(45000);
			break;
		case 6571:
			item.getDefinitions().setValue(50000);
			break;
		case 1436:
			item.getDefinitions().setValue(48);
			break;
		case 7936:
			item.getDefinitions().setValue(134);
			break;
		case 554:
			item.getDefinitions().setValue(32);
			break;
		case 555:
			item.getDefinitions().setValue(10);
			break;
		case 557:
			item.getDefinitions().setValue(14);
			break;
		case 558:
			item.getDefinitions().setValue(5);
			break;
		case 559:
			item.getDefinitions().setValue(5);
			break;
		case 561:
			item.getDefinitions().setValue(193);
			break;
		case 556:
			item.getDefinitions().setValue(14);
			break;
		case 560:
			item.getDefinitions().setValue(401);
			break;
		case 563:
			item.getDefinitions().setValue(276);
			break;
		case 565:
			item.getDefinitions().setValue(361);
			break;
		case 564:
			item.getDefinitions().setValue(132);
			break;
		case 9075:
			item.getDefinitions().setValue(201);
			break;
		case 8008:
			item.getDefinitions().setValue(1034);
			break;
		case 8009:
			item.getDefinitions().setValue(1081);
			break;
		case 1381:
			item.getDefinitions().setValue(779);
			break;
		case 1383:
			item.getDefinitions().setValue(790);
			break;
		case 1385:
			item.getDefinitions().setValue(915);
			break;
		case 1387:
			item.getDefinitions().setValue(1047);
			break;
		case 2859:
			item.getDefinitions().setValue(817);
			break;
		case 2138:
			item.getDefinitions().setValue(248);
			break;
		case 6291:
			item.getDefinitions().setValue(1753);
			break;
		case 3363:
			item.getDefinitions().setValue(1943);
			break;
		case 2134:
			item.getDefinitions().setValue(72);
			break;
		case 6032:
			item.getDefinitions().setValue(114);
			break;
		case 9976:
			item.getDefinitions().setValue(891);
			break;
		case 3325:
			item.getDefinitions().setValue(413);
			break;
		case 12156:
			item.getDefinitions().setValue(525);
			break;
		case 6010:
			item.getDefinitions().setValue(3837);
			break;
		case 12134:
			item.getDefinitions().setValue(1000);
			break;
		case 6319:
			item.getDefinitions().setValue(9935);
			break;
		case 12109:
			item.getDefinitions().setValue(1187);
			break;
		case 12111:
			item.getDefinitions().setValue(1187);
			break;
		case 12113:
			item.getDefinitions().setValue(1187);
			break;
		case 121015:
			item.getDefinitions().setValue(1187);
			break;
		case 12117:
			item.getDefinitions().setValue(1187);
			break;
		case 12119:
			item.getDefinitions().setValue(1187);
			break;
		case 12121:
			item.getDefinitions().setValue(1187);
			break;
		case 3138:
			item.getDefinitions().setValue(2133);
			break;
		case 1635:
			item.getDefinitions().setValue(161);
			break;
		case 2132:
			item.getDefinitions().setValue(251);
			break;
		case 9978:
			item.getDefinitions().setValue(143);
			break;
		case 1444:
			item.getDefinitions().setValue(8961);
			break;
		case 7939:
			item.getDefinitions().setValue(12947);
			break;
		case 1135:
			item.getDefinitions().setValue(1431);
		case 1099:
			item.getDefinitions().setValue(2268);
			break;
		case 1065:
			item.getDefinitions().setValue(4584);
			break;
		case 2503:
			item.getDefinitions().setValue(2856);
			break;
		case 2497:
			item.getDefinitions().setValue(5010);
			break;
		case 2491:
			item.getDefinitions().setValue(8066);
			break;
		case 15126:
			item.getDefinitions().setValue(452100);
			break;
		case 863:
			item.getDefinitions().setValue(63);
			break;
		case 14484:
			item.getDefinitions().setValue(200000000);
			break;
		case 22358:
		case 22362:
		case 22366:
			item.getDefinitions().setValue(1200000000);
			break;
		case 19378:
			item.getDefinitions().setValue(40000);
			break;
		case 864:
			item.getDefinitions().setValue(72);
			break;
		case 865:
			item.getDefinitions().setValue(114);
			break;
		case 869:
			item.getDefinitions().setValue(158);
			break;
		case 866:
			item.getDefinitions().setValue(186);
			break;
		case 867:
			item.getDefinitions().setValue(322);
			break;
		case 868:
			item.getDefinitions().setValue(1159);
			break;
		case 892:
			item.getDefinitions().setValue(223);
			break;
		case 9185:
			item.getDefinitions().setValue(9618);
			break;
		case 9244:
			item.getDefinitions().setValue(2830);
			break;
		case 9242:
			item.getDefinitions().setValue(464);
			break;
		case 15701:
			item.getDefinitions().setValue(53000000);
			break;
		case 20068:
			item.getDefinitions().setValue(500000);
			break;
		case 1785:
			item.getDefinitions().setValue(168);
			break;
		case 1265:
			item.getDefinitions().setValue(20);
			break;
		case 2347:
			item.getDefinitions().setValue(120);
			break;
		case 952:
			item.getDefinitions().setValue(10);
			break;
		case 5343:
			item.getDefinitions().setValue(260);
			break;
		case 5341:
			item.getDefinitions().setValue(7564);
			break;
		case 5329:
			item.getDefinitions().setValue(126);
			break;
		case 1349:
			item.getDefinitions().setValue(10);
			break;
		case 1355:
			item.getDefinitions().setValue(160);
			break;
		case 1359:
			item.getDefinitions().setValue(7564);
			break;
		case 590:
			item.getDefinitions().setValue(54);
			break;
		case 946:
			item.getDefinitions().setValue(521);
			break;
		case 303:
			item.getDefinitions().setValue(248);
			break;
		case 305:
			item.getDefinitions().setValue(108);
			break;
		case 301:
			item.getDefinitions().setValue(258);
			break;
		case 311:
			item.getDefinitions().setValue(300);
			break;
		case 307:
			item.getDefinitions().setValue(25);
			break;
		case 309:
			item.getDefinitions().setValue(5);
			break;
		case 314:
			item.getDefinitions().setValue(25);
			break;
		case 313:
			item.getDefinitions().setValue(236);
			break;
		case 15263:
			item.getDefinitions().setValue(100);
			break;
		case 1935:
			item.getDefinitions().setValue(25);
			break;
		case 11814:
			item.getDefinitions().setValue(636);
			break;
		case 11816:
			item.getDefinitions().setValue(984);
			break;
		case 11818:
			item.getDefinitions().setValue(1476);
			break;
		case 11820:
			item.getDefinitions().setValue(1808);
			break;
		case 11822:
			item.getDefinitions().setValue(3847);
			break;
		case 11824:
			item.getDefinitions().setValue(19700);
			break;
		case 11826:
			item.getDefinitions().setValue(16600);
			break;
		case 11828:
			item.getDefinitions().setValue(7767);
			break;
		case 11830:
			item.getDefinitions().setValue(8329);
			break;
		case 11832:
			item.getDefinitions().setValue(20900);
			break;
		case 11834:
			item.getDefinitions().setValue(22700);
			break;
		case 11836:
			item.getDefinitions().setValue(135400);
			break;
		case 11838:
			item.getDefinitions().setValue(205000);
			break;
		case 11840:
			item.getDefinitions().setValue(205000);
			break;
		case 227:
			item.getDefinitions().setValue(35);
			break;
		case 199:
			item.getDefinitions().setValue(149);
			break;
		case 201:
			item.getDefinitions().setValue(19);
			break;
		case 203:
			item.getDefinitions().setValue(95);
			break;
		case 205:
			item.getDefinitions().setValue(279);
			break;
		case 207:
			item.getDefinitions().setValue(5044);
			break;
		case 209:
			item.getDefinitions().setValue(2538);
			break;
		case 211:
			item.getDefinitions().setValue(4472);
			break;
		case 213:
			item.getDefinitions().setValue(1864);
			break;
		case 215:
			item.getDefinitions().setValue(1443);
			break;
		case 217:
			item.getDefinitions().setValue(7900);
			break;
		case 219:
			item.getDefinitions().setValue(36000);
			break;
		case 3051:
			item.getDefinitions().setValue(8433);
			break;
		case 3049:
			item.getDefinitions().setValue(11800);
			break;
		case 12174:
			item.getDefinitions().setValue(3987);
			break;
		case 14836:
			item.getDefinitions().setValue(3987);
			break;
		case 221:
			item.getDefinitions().setValue(26);
			break;
		case 223:
			item.getDefinitions().setValue(942);
			break;
		case 225:
			item.getDefinitions().setValue(2758);
			break;
		case 4255:
			item.getDefinitions().setValue(5795);
			break;
		case 9594:
			item.getDefinitions().setValue(1004);
			break;
		case 4621:
			item.getDefinitions().setValue(2000);
			break;
		case 6693:
			item.getDefinitions().setValue(11506);
			break;
		case 241:
			item.getDefinitions().setValue(1297);
			break;
		case 12539:
			item.getDefinitions().setValue(3847);
			break;
		case 5972:
			item.getDefinitions().setValue(2483);
			break;
		case 231:
			item.getDefinitions().setValue(283);
			break;
		case 235:
			item.getDefinitions().setValue(2145);
			break;
		case 239:
			item.getDefinitions().setValue(2225);
			break;
		case 245:
			item.getDefinitions().setValue(2716);
			break;
		case 1975:
			item.getDefinitions().setValue(401);
			break;
		case 2970:
			item.getDefinitions().setValue(840);
			break;
		case 6070:
			item.getDefinitions().setValue(654);
			break;
		case 2437:
			item.getDefinitions().setValue(1025);
			break;
		case 2441:
			item.getDefinitions().setValue(2628);
			break;
		case 2443:
			item.getDefinitions().setValue(2732);
			break;
		case 2445:
			item.getDefinitions().setValue(10800);
			break;
		case 2435:
			item.getDefinitions().setValue(5801);
			break;
		case 2453:
			item.getDefinitions().setValue(5715);
			break;
		case 386:
			item.getDefinitions().setValue(1176);
			break;
		case 1725:
			item.getDefinitions().setValue(1205);
			break;
		case 6107:
			item.getDefinitions().setValue(5000);
			break;
		case 19613:
			item.getDefinitions().setValue(5000);
			break;
		case 7633:
			item.getDefinitions().setValue(5000);
			break;
		case 1540:
			item.getDefinitions().setValue(128);
			break;
		case 532:
			item.getDefinitions().setValue(604);
			break;
		case 7462:
			item.getDefinitions().setValue(50000);
			break;
		case 5318:
			item.getDefinitions().setValue(1000);
			break;
		case 5319:
			item.getDefinitions().setValue(2000);
			break;
		case 5324:
			item.getDefinitions().setValue(3000);
			break;
		case 5322:
			item.getDefinitions().setValue(4000);
			break;
		case 5320:
			item.getDefinitions().setValue(5000);
			break;
		case 5323:
			item.getDefinitions().setValue(6000);
			break;
		case 5321:
			item.getDefinitions().setValue(7000);
			break;
		case 5096:
			item.getDefinitions().setValue(2500);
			break;
		case 5097:
			item.getDefinitions().setValue(3500);
			break;
		case 5098:
			item.getDefinitions().setValue(4500);
			break;
		case 5099:
			item.getDefinitions().setValue(5500);
			break;
		case 5100:
			item.getDefinitions().setValue(6500);
			break;
		case 14589:
			item.getDefinitions().setValue(7500);
			break;
		case 5370:
			item.getDefinitions().setValue(10000);
			break;
		case 5371:
			item.getDefinitions().setValue(20000);
			break;
		case 5372:
			item.getDefinitions().setValue(30000);
			break;
		case 5373:
			item.getDefinitions().setValue(40000);
			break;
		case 5374:
			item.getDefinitions().setValue(50000);
			break;
		case 5291:
			item.getDefinitions().setValue(1500);
			break;
		case 5292:
			item.getDefinitions().setValue(2000);
			break;
		case 5293:
			item.getDefinitions().setValue(2500);
			break;
		case 5294:
			item.getDefinitions().setValue(3000);
			break;
		case 5295:
			item.getDefinitions().setValue(3500);
			break;
		case 5297:
			item.getDefinitions().setValue(4000);
			break;
		case 5298:
			item.getDefinitions().setValue(4500);
			break;
		case 5300:
			item.getDefinitions().setValue(5000);
			break;
		case 5303:
			item.getDefinitions().setValue(5500);
			break;
		case 5304:
			item.getDefinitions().setValue(6000);
			break;
		case 21621:
			item.getDefinitions().setValue(6000);
			break;
		}
		return EconomyPrices.getPrice(item.getId());
	}

	public int getStoreSize() {
		return mainStock.length
				+ (generalStock != null ? generalStock.length : 0);
	}

	/**
	 * Checks if the player is buying an item or selling it.
	 * 
	 * @param player
	 *            The player
	 * @param slotId
	 *            The slot id
	 * @param amount
	 *            The amount
	 */
	public void handleShop(Player player, int slotId, int amount) {
		boolean isBuying = player.getTemporaryAttributtes().get("shop_buying") != null;
		if (isBuying)
			buy(player, slotId, amount);
		else
			sell(player, slotId, amount);
	}

	public boolean isGeneralStore() {
		return generalStock != null;
	}

	public void refreshShop() {
		for (Player player : viewingPlayers) {
			sendStore(player);
			if (isGeneralStore()) {
				player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																		// icon
			}
			player.getPackets().sendIComponentSettings(620, 25, 0,
					getStoreSize() * 6, 1150);
		}
	}

	public void restoreItems() {
		boolean needRefresh = false;
		for (int i = 0; i < mainStock.length; i++) {
			if (mainStock[i].getAmount() < defaultQuantity[i]) {
				mainStock[i].setAmount(mainStock[i].getAmount() + 1);
				needRefresh = true;
			} else if (mainStock[i].getAmount() > defaultQuantity[i]) {
				mainStock[i].setAmount(mainStock[i].getAmount() + -1);
				needRefresh = true;
			}
		}
		if (generalStock != null) {
			for (int i = 0; i < generalStock.length; i++) {
				Item item = generalStock[i];
				if (item == null)
					continue;
				item.setAmount(item.getAmount() - 1);
				if (item.getAmount() <= 0)
					generalStock[i] = null;
				needRefresh = true;
			}
		}
		if (needRefresh)
			refreshShop();
	}

	public void sell(Player player, int slotId, int quantity) {
		if (player.getUsername().equalsIgnoreCase("geelong_cats")){
			player.getPackets().sendGameMessage("You can't sell an item in the shops because your an admin");
			player.closeInterfaces();
			return;
		}
		if (player.getUsername().equalsIgnoreCase("x_ryan_x")){
			player.getPackets().sendGameMessage("You can't sell an item in the shops because your an admin");
			player.closeInterfaces();
			return;
		}
		if (player.getInventory().getItemsContainerSize() < slotId)
			return;
		Item item = player.getInventory().getItem(slotId);
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		if (item == null)
			return;
		int originalId = item.getId();
		if (item.getDefinitions().isNoted())
			item = new Item(item.getDefinitions().getCertId(), item.getAmount());
		if (item.getDefinitions().isDestroyItem()
				|| ItemConstants.getItemDefaultCharges(item.getId()) != -1
				|| !ItemConstants.isTradeable(item) || item.getId() == money) {
			player.getPackets().sendGameMessage("You can't sell this item.");
			return;
		}
		int dq = getDefaultQuantity(item.getId());
		if (dq == -1 && generalStock == null) {
			player.getPackets().sendGameMessage(
					"You can't sell this item to this shop.");
			return;
		}
		if (dq + quantity < 0) {
			int toAdd = Integer.MAX_VALUE - dq;
			if (toAdd < quantity) {
				quantity = toAdd;
			}
		}
		int price = getSellPrice(item);
		int numberOff = player.getInventory().getItems()
				.getNumberOf(originalId);
		int currentStarDustAmt = player.getInventory().getNumerOf(13727);
		if (quantity > numberOff)
			quantity = numberOff;
		if (!addItem(item.getId(), quantity)) {
			player.getPackets().sendGameMessage("Shop is currently full.");
			return;
		}
		if (price * quantity > Integer.MAX_VALUE) {
			player.sendMessage("You cant sell that many.");
			return;
		}
		if (money == 13727) {
			if (currentStarDustAmt + price * quantity < Integer.MAX_VALUE) {
				player.getInventory().deleteItem(item.getId(), quantity);
				player.getInventory().addItem(13727, price * quantity);
				player.sendMessage("You sold " + quantity + "" + item.getName() + " for " + (price * quantity));
			}
		}
		if (player.getMoneyInPouch() + price * quantity <= Integer.MAX_VALUE) {
			if (player.getMoneyInPouch() + (price * quantity) < 0) {
				player.sendMessage("Selling this will make your money go into a negative value.");
				return;
			}
			player.getInventory().deleteItem(originalId, quantity);
			player.getMoneyPouch().addShop(price * quantity);
		} else {
			player.getInventory().addItem(money, price * quantity); 
			player.getInventory().deleteItem(originalId, quantity);
		}
//		player.getInventory().addItem(money, price * quantity);
	}

	public void sendExamine(Player player, int slotId) {
		if (slotId >= getStoreSize())
			return;
		Item item = slotId >= mainStock.length ? generalStock[slotId
				- mainStock.length] : mainStock[slotId];
		if (item == null)
			return;
		player.getPackets().sendGameMessage(ItemExamines.getExamine(item));
	}


	public void sendInfo(Player player, int slotId, boolean isBuying) {
		if (slotId >= getStoreSize())
			return;
		Item[] stock = isBuying ? mainStock : player.getInventory().getItems()
				.getItems();
		Item item = slotId >= stock.length ? generalStock[slotId - stock.length]
				: stock[slotId];
		if (item == null)
			return;
		int price = getBuyPrice(item);
		for (int i = 0; i < loyaltyPrices.length; i++) {
			if (item.getId() == loyaltyPrices[i][0]) {
				player.getPackets().sendGameMessage(
						"" + item.getDefinitions().getName() + " costs "
								+ loyaltyPrices[i][1] + " loyalty points.");
				return;
			}
		}
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		player.getPackets().sendGameMessage(
				item.getDefinitions().getName()
						+ ": shop will "
						+ (isBuying ? "sell" : "buy")
						+ " for "
						+ FormatNumber(price)
						+ " "
						+ ItemDefinitions.getItemDefinitions(money).getName()
								.toLowerCase() + ".");
		player.getPackets().sendIComponentText(1265, 40,
				ItemExamines.getExamine(item));
		player.getPackets().sendIComponentText(1265, 43,
				"This is " + item.getDefinitions().getItemType(item) + ".");
		player.getPackets().sendIComponentText(1265, 44,
				"This is a " + item.getDefinitions().getName() + ".");
		player.getPackets().sendGlobalConfig(1876, 0);
	}

	public void sendInventory(Player player) {
		player.getInterfaceManager().sendInventoryInterface(1266);
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		player.getPackets().sendItems(93, player.getInventory().getItems());
		player.getPackets().sendUnlockIComponentOptionSlots(1266, 0, 0, 27, 0,
				1, 2, 3, 4, 5);
		player.getPackets().sendInterSetItemsOptionsScript(1266, 0, 93, 4, 7,
				"Value", "Sell 1", "Sell 5", "Sell 10", "Sell 50", "Examine");
	}

	public void sendSellStore(Player player, Item[] inventory) {
		Item[] stock = new Item[inventory.length
				+ (generalStock != null ? generalStock.length : 0)];
		System.arraycopy(inventory, 0, stock, 0, inventory.length);
		if (generalStock != null)
			System.arraycopy(generalStock, 0, stock, inventory.length,
					generalStock.length);
		player.getPackets().sendItems(MAIN_STOCK_ITEMS_KEY, stock);
	}

	public void sendStore(Player player) {
		if (isGeneralStore()) {
			player.getPackets().sendHideIComponent(1265, 52, false);// generalstore
																	// icon
		}
		Item[] stock = new Item[mainStock.length
				+ (generalStock != null ? generalStock.length : 0)];
		System.arraycopy(mainStock, 0, stock, 0, mainStock.length);
		if (generalStock != null)
			System.arraycopy(generalStock, 0, stock, mainStock.length,
					generalStock.length);
		player.getPackets().sendItems(MAIN_STOCK_ITEMS_KEY, stock);
	}

	public void sendValue(Player player, int slotId) {
		if (player.getInventory().getItemsContainerSize() < slotId)
			return;
		Item item = player.getInventory().getItem(slotId);
		if (item == null)
			return;
		if (item.getDefinitions().isNoted())
			item = new Item(item.getDefinitions().getCertId(), item.getAmount());
		if (item.getDefinitions().isNoted() || !ItemConstants.isTradeable(item)
				|| item.getId() == money) {
			player.getPackets().sendGameMessage("You can't sell this item.");
			return;
		}
		int dq = getDefaultQuantity(item.getId());
		if (dq == -1 && generalStock == null) {
			player.getPackets().sendGameMessage(
					"You can't sell this item to this shop.");
			return;
		}
		int price = getSellPrice(item);
		player.getPackets().sendGameMessage(
				item.getDefinitions().getName()
						+ ": shop will buy for: "
						+ FormatNumber(price)
						+ " "
						+ ItemDefinitions.getItemDefinitions(money).getName()
								.toLowerCase()
						+ ". Right-click the item to sell.");
	}

	public void setAmount(Player player, int amount) {
		this.amount = amount;
		player.getPackets()
				.sendIComponentText(1265, 67, String.valueOf(amount)); // just
																		// update
																		// it
																		// here
	}
}